package com.androidcentralmedias;

import java.io.OutputStreamWriter;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddEndereco extends Activity {
	public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.newendereco);
        final Button salvar = (Button) findViewById(R.id.salvar);
        final Button limpar = (Button) findViewById(R.id.limpar);
        final Button addIP = (Button) findViewById(R.id.addIP);
        final EditText nome = (EditText) findViewById(R.id.nome);
        final EditText ip = (EditText) findViewById(R.id.ip);
        final EditText canal = (EditText) findViewById(R.id.canal);
        salvar.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	try {
            		  OutputStreamWriter out = new OutputStreamWriter(openFileOutput("enderecos.txt",Context.MODE_APPEND)); //Context.MODE_APPEND eh para escrever depois da ultima linha de texto
            		  out.write(nome.getText().toString() + "\n");
            		  out.write(ip.getText().toString() + "\n");
            		  out.write(canal.getText().toString() + "\n");
            		  out.close();
            		  AddEndereco.this.finish();
            		} catch (java.io.IOException e) {
            		}
            	
            	}});
        addIP.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	try {
            		  OutputStreamWriter out = new OutputStreamWriter(openFileOutput("enderecos.txt",Context.MODE_APPEND)); //Context.MODE_APPEND eh para escrever depois da ultima linha de texto
            		  out.write(nome.getText().toString() + "\n");
            		  out.write(ip.getText().toString() + "\n");
            		  out.write(canal.getText().toString() + "\n");
            		  out.close();
            		  AddEndereco.this.finish();
            		} catch (java.io.IOException e) {
            		}
            	
            	}});
        limpar.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	try {
            		  OutputStreamWriter out = new OutputStreamWriter(openFileOutput("enderecos.txt",0)); //Context.MODE_APPEND eh para escrever depois da ultima linha de texto
            		  out.write("");
            		  out.close();
            		} catch (java.io.IOException e) {
            		}
            	
            	}});
    }
}
